package com.tour.service.impl;

import com.tour.bean.ReturnT;
import com.tour.bean.UserMessage;
import com.tour.dao.UserMessageMapper;
import com.tour.service.UserMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * user_message
 * @author
 * @date 2020/03/18
 */
@Service
public class UserMessageServiceImpl implements UserMessageService {

    @Autowired
    private UserMessageMapper userMessageMapper;


    @Override
    public ReturnT<String> insert(UserMessage userMessage) {

        // valid
        if (userMessage == null) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, "必要参数缺失");
        }

        userMessageMapper.insert(userMessage);
        return ReturnT.SUCCESS;
    }


    @Override
    public ReturnT<String> delete(int id) {
        int ret = userMessageMapper.delete(id);
        return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
    }


    @Override
    public ReturnT<String> update(UserMessage userMessage) {
        int ret = userMessageMapper.update(userMessage);
        return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
    }


    @Override
    public UserMessage load(int id) {
        return userMessageMapper.load(id);
    }


    @Override
    public Map<String,Object> pageList(int offset, int pagesize) {

        List<UserMessage> pageList = userMessageMapper.pageList(offset, pagesize);
        int totalCount = userMessageMapper.pageListCount();

        // result
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("pageList", pageList);
        result.put("totalCount", totalCount);

        return result;
    }

    @Override
    public List<Map<String, Object>> getMsgByModel(String modType, int modId) {
        Map<String,Object> param=new HashMap<>();
        param.put("modType", modType);
        param.put("modId",modId);
        return userMessageMapper.getMsgByModel(param);
    }

}

